package com.erp.module.JiJianCaiJi

import android.content.Context
import com.erp.contacts.Contacts
import com.erp.contacts.Contacts.BOUNDARY
import com.erp.Interface.OnUserDataInterface
import com.erp.util.Httputil.*
import org.xutils.http.HttpMethod
import org.xutils.http.RequestParams
import org.xutils.x

/**
 * Created by Administrator on 2019/3/19/019.
 * 作者：刘洋
 */
class JiJianCaiJiModel : JiJianCaiJiContract.JiJianCaiJiMP {
    override fun getJiJianCaiJiLieBiao(context: Context, page: Int, pagesize: Int, name: String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.JIJIAN_CAIJI_LIEBIAO)
        getparams(context, params)
        addtoken(params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        params.addBodyParameter("searchParams[creator_name]", name)
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }

    override fun setJiJianCaiJi(context: Context, mcode: String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.JIJIAN_CAIJI_SHANGCHUAN)
        getparams(context, params)
        addtoken(params)
        params.addBodyParameter("", "", BOUNDARY)
        params.addBodyParameter("mcode", mcode, BOUNDARY)
        x.http().post(params, Call(context, onUserDataInterface))
    }

    override fun deleteJiJianCaiJi(context: Context, id: String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.DELETE_JIJIAN_CAIJI + id)
        getparams(context, params)
        addtoken(params)
        x.http().request(HttpMethod.DELETE, params, Call(context, onUserDataInterface))
    }
}